function [iter, istate, c, cjac, clamda, objf1, objgrd, r, theta1, user, lwsav, iwsav,rwsav, ifail] = e04uc_global(a_constr, bl, bu, confun_ref, objfun_ref, istate, cjac, clamda,r, theta0_mat, lwsav, iwsav, rwsav, txt1, n, txt2, nclin, txt3, ncnln,txt4, user)

reps=size(theta0_mat,2);
objf_vec=NaN*ones(reps,1);
objf_vec_ext=NaN*ones(reps,1);

assert(reps==1)

for rr=1:reps,
    results_run(rr).iter=NaN;
    results_run(rr).istate=NaN;
    results_run(rr).c=NaN;
    results_run(rr).cjac=NaN;
    results_run(rr).clamda=NaN;
    results_run(rr).objf1=NaN;
    results_run(rr).objgrd=NaN;
    results_run(rr).r=NaN;
    results_run(rr).theta1=NaN;
    results_run(rr).user=NaN;
    results_run(rr).lwsav=NaN;
    results_run(rr).iwsav=NaN;
    results_run(rr).rwsav=NaN;
    results_run(rr).ifail=NaN;
	results_run(rr).tstart=NaN;
end

for rr=1:reps

    nag_issue_warnings_wrap;
    warning('off', 'NAG:warning');

    theta0=theta0_mat(:,rr);
	results_run(rr).tstart=tic;

	[cwsav,lwsav,iwsav,rwsav,ifail] = e04wb('e04uc');
	[lwsav, iwsav, rwsav, inform] = e04ue('Print Level = 1', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('nolist', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Major Print Level==0', lwsav, iwsav,rwsav); 
	[lwsav, iwsav, rwsav, inform] = e04ue('Col', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('derivative level=3', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Hessian=no', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Major Iteration Limit==500', lwsav, iwsav,rwsav);  
	[lwsav, iwsav, rwsav, inform] = e04ue('Step Limit==1', lwsav, iwsav,rwsav); 
	[lwsav, iwsav, rwsav, inform] = e04ue('Minor Print Level==0', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Monitoring File==-1', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Verify Level == -1', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Stop Objective Check at Variable == 46', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Stop Constraint Check at Variable == 3', lwsav, iwsav,rwsav);
	[lwsav, iwsav, rwsav, inform] = e04ue('Function Precision == 1e-4', lwsav, iwsav,rwsav); 
	[lwsav, iwsav, rwsav, inform] = e04ue('Optimality Tolerance == 1e-3', lwsav, iwsav,rwsav); 
           
    [results_run(rr).iter, results_run(rr).istate, results_run(rr).c, results_run(rr).cjac, results_run(rr).clamda, results_run(rr).objf1, results_run(rr).objgrd, results_run(rr).r, results_run(rr).theta1, results_run(rr).user, results_run(rr).lwsav, results_run(rr).iwsav,results_run(rr).rwsav, results_run(rr).ifail] = e04uc(a_constr, bl, bu, confun_ref, objfun_ref, istate, cjac, clamda,r, theta0, lwsav, iwsav, rwsav, 'n', n, 'nclin', nclin, 'ncnln', ncnln,'user', user);      

    if results_run(rr).ifail==0
        objf_vec(rr,1)=results_run(rr).objf1;
    end

    if (results_run(rr).ifail==0 || results_run(rr).ifail==1)
        objf_vec_ext(rr,1)=results_run(rr).objf1;
    end
    
end
    
[~,pos]=min(objf_vec);  
rr=pos;

iter=results_run(rr).iter;
istate=results_run(rr).istate;
c=results_run(rr).c;
cjac=results_run(rr).cjac;
clamda=results_run(rr).clamda;
objf1=results_run(rr).objf1;
objgrd=results_run(rr).objgrd;
r=results_run(rr).r;
theta1=results_run(rr).theta1;
user=results_run(rr).user;
lwsav=results_run(rr).lwsav;
iwsav=results_run(rr).iwsav;
rwsav=results_run(rr).rwsav;
ifail=results_run(rr).ifail;

    %        
